home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- *
- * @@@BUILDINFO@@@ 35breakpointsPane.jsx 1.0.0.47 07-Feb-2005
- * Copyright 2005 Adobe Systems Incorporated
- * All Rights Reserved.
- *
- * NOTICE: All information contained herein is, and remains the property of
- * Adobe Systems Incorporated and its suppliers, if any. The intellectual
- * and technical concepts contained herein are proprietary to Adobe Systems
- * Incorporated and its suppliers and may be covered by U.S. and Foreign
- * Patents,patents in process,and are protected by trade secret or copyright
- * law. Dissemination of this information or reproduction of this material
- * is strictly forbidden unless prior written permission is obtained from
- * Adobe Systems Incorporated.
- **************************************************************************/
-
- // Code to add to the Breakpoints pane
- // window.breakpoints is a LiveObject. We add methods to it which can
- // be invoked from C++ as well as scripts
-
- // Global properties used:
- // window: LiveObject representing the main window
- // document: LiveObject representing the currently active document (script)
-
- // When a breakpoints list item is selected, highlight the script line it
- // refers to
-
- window.breakpoints.list.onChange = function ()
- {
- if (this.selection != null && document != null) {
- document.setSelection (document.lineToOffset (this.selection.bpInfo.line));
- }
- } // onChange
-
-
- // When a breakpoints list item is double-clicked, show the Change Breakpoint
- // dialog for the breakpoint it refers to
-
- window.breakpoints.list.onDoubleClick = function ()
- {
- if (this.selection != null) {
- this.parent.changeBP ();
- }
- } // onDoubleClick
-
-
- // update()
- // update the contents of the BreakpointsPane for the current script
-
- window.breakpoints.update = function ()
- {
- // start clean
- this.invalidate();
-
- // Get the current script (document)
- if (document == undefined || document == null)
- return;
- var script = document;
-
- // Get all the BPs for the current script and add them to the list
- var bpsList = script.getAllBP();
- var numBPs = bpsList.length;
- for (bpIdx = 0; bpIdx < numBPs; bpIdx++) {
- var bpInfo = bpsList[bpIdx];
- var hasCondition = (bpInfo.condition != undefined);
- var line = bpInfo.line + 1;
- var text = localize ("$$$/ESToolkit/Panes/Breakpoints/List/Line= Line %1", line);
- if (hasCondition)
- text += localize ("$$$/ESToolkit/Panes/Breakpoints/List/When= when (%1)", bpInfo.condition);
- var bpItem = this.list.add ('item', text);
- bpItem.icon = (bpInfo.enabled ?
- (hasCondition ? "BreakpointEnabledCond" : "BreakpointEnabled" )
- :
- (hasCondition ? "BreakpointDisabledCond" : "BreakpointDisabled"));
- // Remember the BP info so it can be accessed when this list item is selected
- bpItem.bpInfo = bpInfo;
- }
- } // update
-
-
- // invalidate() is called when the current script is closed or deactivated
-
- window.breakpoints.invalidate = function ()
- {
- // Erase the current BPs list
- this.list.selection = null;
- this.list.removeAll();
- } // invalidate
-
-
- // bool canAddBP()
- // Return true if a new breakpoint can be created (i.e., there is a current script)
-
- window.breakpoints.canAddBP = function ()
- {
- return (document != undefined && document != null);
- } // canAddBP
-
-
- // bool canChangeBP()
- // Return true if a breakpoint is selected and can be modified
-
- window.breakpoints.canChangeBP = function ()
- {
- return this.list.selection != null;
- } // canChangeBP
-
-
- // bool canRemoveBP()
- // Return true if a breakpoint is selected and can be removed
-
- window.breakpoints.canRemoveBP = function ()
- {
- return this.list.selection != null;
- } // canRemoveBP
-
-
- // bool addBP()
- // Show a dialog to add a new breakpoint to the current script
-
- window.breakpoints.addBP = function ()
- {
- // Create a dialog for defining a new breakpoint
- var dlg = new Window (this.addChangeDlg.resourceSpec);
- dlg.text = localize("$$$/ESToolkit/AddChangeBPDlg/titleAddBP=Add Breakpoint");
-
- // Initial state
- dlg.body.props.le.enabledCb.value = true;
-
- // Define event handlers
- dlg.onShow = this.addChangeDlg.onShow;
- dlg.onClose = this.addChangeDlg.onClose;
- dlg.btns.ok.onClick = this.addChangeDlg.btnOnClick;
- dlg.btns.cancel.onClick = this.addChangeDlg.btnOnClick;
- // Don't want the 'Remove' button for the Add dialog
- dlg.btns.remove (dlg.btns.removeBP);
-
- dlg.center();
- if (dlg.show() == 1) {
- // Define a new BP
- with (dlg.body.props) {
- var line = le.line.text - 1;
- var enabled = le.enabledCb.value != 0;
- var cond = null;
- if (condition.text.length > 0)
- cond = condition.text;
- document.restoreBP (line, enabled, cond);
- }
- this.update();
- }
- } // addBP
-
-
- // bool changeBP()
- // Show a dialog to add a new breakpoint to the current script
-
- window.breakpoints.changeBP = function ()
- {
- // Create a dialog for editing the BP info
- var dlg = new Window (this.addChangeDlg.resourceSpec);
- dlg.text = localize ("$$$/ESToolkit/AddChangeBPDlg/titleChangeBP=Change Breakpoint");
-
- // Initialize it with current BP info
- var bpInfo = window.breakpoints.list.selection.bpInfo;
- with (dlg.body.props.le) {
- line.text = bpInfo.line + 1;
- enabledCb.value = bpInfo.enabled;
- }
- dlg.body.props.condition.text = bpInfo.condition != undefined ? bpInfo.condition : "";
-
- dlg.onShow = this.addChangeDlg.onShow;
- dlg.onClose = this.addChangeDlg.onClose;
- dlg.btns.ok.onClick = this.addChangeDlg.btnOnClick;
- dlg.btns.cancel.onClick = this.addChangeDlg.btnOnClick;
- dlg.btns.removeBP.onClick = this.addChangeDlg.btnOnClick;
-
- dlg.center();
- var action = dlg.show();
- if (action == 1) {
- // Change this breakpoint:
- // delete the current one and create one with the new properties
- document.clearBP (bpInfo.line);
- with (dlg.body.props) {
- var line = le.line.text - 1;
- var enabled = le.enabledCb.value != 0;
- var cond = null;
- if (condition.text.length > 0)
- cond = condition.text;
- document.restoreBP (line, enabled, cond);
- }
- this.update();
- }
- else if (action == 3) {
- // Delete this breakpoint
- document.clearBP (bpInfo.line);
- this.update();
- }
- } // changeBP
-
-
- // bool removeBP()
- // Show a dialog to add a new breakpoint to the current script
-
- window.breakpoints.removeBP = function ()
- {
- var line = this.list.selection.bpInfo.line;
- document.clearBP (line);
- this.update();
- } // removeBP
-
- // void editBP()
- // Select and change a breakpoint at the given line. Used by the Editor context menu.
-
- window.breakpoints.editBP = function (line)
- {
- // find the BP
- for (var i = 0; i < this.list.items.length; i++)
- {
- if (this.list.items [i].bpInfo.line == line)
- {
- this.list.selection = this.list.items [i];
- this.changeBP();
- break;
- }
- }
- }
-
- //////////////////////////////////////////////////////////////////////
- // Dialog utility functions and resources
-
- window.breakpoints.addChangeDlg = {
-
- // an onShow event callback function for the add/change dialog.
- // It is used to adjust the position of text labels to align
- // with corresponding edit fields.
-
- onShow: function ()
- {
- // Position labels in alignment with corresponding edit fields
- with (this.body) {
- labels.size.height = props.size.height;
- var lineEditHt = props.le.line.size.height;
- labels.line.location.y = props.le.location.y + ((lineEditHt - labels.line.size.height) / 2);
- labels.condition.location.y = props.condition.location.y;
- }
- }, // onShow
-
- // an onClose event callback function for the add/change dialog.
- // It returns 'false' if the dialog was dismissed by the OK button and
- // any field contains an invalid value.
- onClose: function ()
- {
- var ok = true;
- if (this.okButtonClicked) {
- /* Must validate the specified line number and any 'condition'
- specified before allowing the dialog to close */
- var lineNum = this.body.props.le.line.text;
- ok = (lineNum >= 0) && (lineNum < document.lines.length);
- if (! ok) {
- errorBox ("$$$/ESToolkit/Alerts/LineNumberError=Line number out of range");
- }
- if (ok && this.body.props.condition.text.length > 0) {
- var cond = this.body.props.condition.text;
- if (cond.indexOf ('\n') >= 0 || cond.indexOf ('\r') >= 0) {
- /* newline characters or cr/nl pairs in the condition mess up evaluation
- and mess up display of the condition, so replace any line control chars with spaces */
- cond = cond.replace (/\r/g, ' ');
- cond = cond.replace (/\n/g, ' ');
- this.body.props.condition.text = cond;
- }
- // checkSyntax returns true, or an error message string
- ok = Document.checkSyntax (this.body.props.condition.text);
- if (ok != true) {
- errorBox ("$$$/ESToolkit/Alerts/ConditionSyntaxError=Syntax Error in condition: %1", ok);
- ok = false; // don't close dialog yet
- }
- }
- this.okButtonClicked = ok;
- }
- return ok;
- }, // onClose
-
- // an onClick event callback for the OK/Cancel/Remove buttons in the add/change dialog
- btnOnClick: function ()
- {
- var dlg = this.parent.parent;
- if (this.properties.name == 'ok') {
- // OK button
- dlg.okButtonClicked = true;
- dlg.close(1);
- }
- else if (this.properties.name == 'cancel')
- // Cancel button
- dlg.close(2);
- else
- // Remove button
- dlg.close(3);
- }, // btnOnClick
-
- // Resource specification for the add/change dialog
- resourceSpec:
- "dialog { \
- orientation:'column', alignChildren:'left', \
- body: Group { \
- orientation:'row', alignChildren:'top', \
- labels: Group { \
- orientation:'column', alignChildren:'right', \
- line: StaticText { \
- text:'$$$/ESToolkit/AddChangeBPDlg/Line=Line:' \
- }, \
- condition: StaticText { \
- text:'$$$/ESToolkit/AddChangeBPDlg/Condition=Condition:' \
- } \
- }, \
- props: Group { \
- orientation:'column', alignChildren:'left', \
- le: Group { \
- line: EditText { \
- preferredSize:[60,20], justify:'right', \
- helpTip:'$$$/ESToolkit/AddChangeBPDlg/htLine=The line number for this breakpoint' \
- }, \
- enabledCb: Checkbox { \
- text:'$$$/ESToolkit/AddChangeBPDlg/Enabled=&Enabled', \
- helpTip:'$$$/ESToolkit/AddChangeBPDlg/htEnabled=Enable or disable this breakpoint' \
- } \
- }, \
- condition: EditText { \
- properties:{ multiline:true, scrolling:true }, \
- preferredSize:[300,40], \
- helpTip:'$$$/ESToolkit/AddChangeBPDlg/htCondition=Enter a JavaScript expression that should evaluate to true before a breakpoint is hit' \
- } \
- } \
- }, \
- btns: Group { \
- alignment:'right', \
- removeBP: Button { \
- text:'$$$/ESToolkit/AddChangeBPDlg/Remove=&Remove', \
- properties:{ name:'remove' } \
- }, \
- gap: StaticText { size:[5,1] }, \
- ok: Button { \
- text:'$$$/CT/ExtendScript/UI/OK=OK', \
- properties:{ name:'ok' } \
- }, \
- cancel: Button { \
- text:'$$$/CT/ExtendScript/UI/Cancel=Cancel', \
- properties:{ name:'cancel' } \
- } \
- } \
- }"
- };
-